home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / Extras / SubMenus / MenuBar.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.5 KB  |  89 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. //////////////////////////////////////////////////////////
  22. // MenuBar.C: A menu bar whose panes support items
  23. //            that execute Cmd's
  24. //////////////////////////////////////////////////////////
  25.  
  26. ////////////////////////////////////////////////////////////
  27. // MODIFIED TO SUPPORT SUBMENUS - not described in Book
  28. ///////////////////////////////////////////////////////////
  29.  
  30.  
  31. #include "MenuBar.h"
  32. #include "Cmd.h"
  33. #include "CmdList.h"
  34. #include "ButtonInterface.h"
  35. #include <Xm/RowColumn.h>
  36. #include <Xm/CascadeB.h>
  37.  
  38. MenuBar::MenuBar ( Widget parent, char *name ) : UIComponent ( name )
  39. {
  40.     // Base widget is a Motif menu bar widget
  41.     
  42.     _w = XmCreateMenuBar ( parent, _name, NULL, 0 );
  43.     
  44.     installDestroyHandler();
  45. }
  46.  
  47. void MenuBar::addCommands ( CmdList *list )
  48. {
  49.     createPulldown ( _w, list );
  50. }
  51.  
  52.  
  53. void MenuBar::createPulldown ( Widget parent, CmdList *list )
  54. {
  55.     int    i;
  56.     Widget pulldown, cascade;
  57.     
  58.     // Create a pulldown menu pane for this list of commands
  59.     
  60.     pulldown = XmCreatePulldownMenu ( parent, list->name(), NULL, 0 );
  61.     
  62.     // Each entry in the menu bar must have a cascade button
  63.     // from which the user can pull down the pane
  64.     
  65.     cascade = XtVaCreateWidget ( list->name(), 
  66.                 xmCascadeButtonWidgetClass,
  67.                 parent, 
  68.                 XmNsubMenuId, pulldown, 
  69.                 NULL );
  70.     XtManageChild ( cascade );
  71.     
  72.     // Loop through the cmdList, creating a menu 
  73.     // entry for each command. 
  74.     
  75.     for ( i = 0; i < list->size(); i++)
  76.     {
  77.     if(!strcmp((*list)[i]->className(), "CmdList"))
  78.     {
  79.         createPulldown( pulldown, (CmdList*) (*list)[i]);
  80.     }
  81.     else
  82.     {
  83.         CmdInterface *ci;
  84.         ci  = new ButtonInterface ( pulldown, (*list)[i] );
  85.         ci->manage();
  86.     }
  87.     }
  88. }
  89.